import wx, wx.html
import sys
from eRecruiterObjects import QualityExplanation 

class HtmlWindow(wx.html.HtmlWindow):
    def __init__(self, parent, id, size=(600,400)):
        wx.html.HtmlWindow.__init__(self,parent, id, size=size)
        if "gtk2" in wx.PlatformInfo:
            self.SetStandardFonts()

    def OnLinkClicked(self, link):
        wx.LaunchDefaultBrowser(link.GetHref())

class ExplanationFrame(wx.Frame):
    def __init__(self, explanations, title = "eRecruiter Explanation" ):
        wx.Frame.__init__(self, None, -1, title ,pos=(150,150), size=(600,600))
        self.Bind(wx.EVT_CLOSE, self.OnClose)

        self.explanations = explanations
        
        sw = wx.ScrolledWindow(self)
        _htmlWin = HtmlWindow(sw, -1, size=(600,600))

        explan_html = ""
        for quality in explanations:
            explan_html += '<table width="580px" cellspacing="0" >'
            explan_html += '<tr bgcolor="#CCCCCC"><td>' + quality.Quality + '</td><td align="right">' + str(quality.Score) + '</td></tr>'
            explan_html += '<tr><td colspan="2"><ul>'
            for fact in quality.ListOfFacts:
                explan_html += '<li>' + fact + '</li>'
            explan_html += '</ul></td></tr>'
            explan_html += '</table>< /br>'
        

        _htmlWin.SetPage(explan_html)
        self.SetClientSize(_htmlWin.GetSize())
        self.CentreOnParent(wx.BOTH)
        self.SetFocus()

    def OnClose(self, event):
        self.Destroy()
